﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser
{
    #region Using Statements

    using System;
    using System.Net;
    using System.Collections;
    using System.Collections.Generic;

    using KLF.Lib.Browser.Events;
    using KLF.Lib.Browser.DOM.HTML;
    using KLF.Lib.Browser.DOM.CSS.SAC.Selectors;

    #endregion

    /// <summary>
    /// IBrowser interface defines the main API for web browsing tasks.
    /// </summary>
    public interface IBrowser
    {
        bool Click();
        bool Click(Selector criteria);

        // History stuff
        bool GoBack();
        bool GoForward();

        bool GoTo(string url);
        bool GoTo(Uri uri);
        bool GoTo(string url, int timeout);
        bool GoTo(Uri uri, int timeout);
        bool GoTo(Uri uri, int timeout, ICredentials user);

        /// <summary>
        /// Load a document from a local file.
        /// </summary>
        /// <param name="filename">The filename to the local document.</param>
        /// <returns>Returns true on success and false on failure.</returns>
        bool LoadFile(string filename);

        /// <summary>
        /// Fires when a page navigation error occurs.
        /// </summary>
        event EventHandler<NavigationErrorArgs> OnNavigationError;

        /// <summary>
        /// Fires after a block of Javascript has executed.
        /// </summary>
        event EventHandler<ScriptPostExecuteArgs> OnPostExecuteScript;

        /// <summary>
        /// Fires just before the DocumentLoader executes a script block.
        /// </summary>
        event EventHandler<ScriptPreExecuteArgs> OnPreExecuteScript;

        /// <summary>
        /// Fires when an exception occurs while executing a script.
        /// </summary>
        event EventHandler<ScriptExceptionArgs> OnScriptException;

        /// <summary>
        /// A collection of options that govern how the browser operates.
        /// </summary>
        BrowserOptions Options { get; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="selector"></param>
        /// <returns></returns>
        FormWrapper Form(Selector selector);

        /// <summary>
        /// Sets a single form value.
        /// </summary>
        /// <param name="criteria">The criteria by which to find the control.</param>
        /// <param name="value">The new value to pass to the control.</param>
        /// <returns>Returns true on success, false if setting the value failed.</returns>
        bool SetValue(Selector criteria, string value);
    }
}
